package com.yyh.io2;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

public class Test3 {
    public static void main2(String[] args) throws IOException {
        Properties pop = new Properties();
        pop.setProperty("name","张三");
        pop.setProperty("age","18");
        pop.setProperty("score","20.3");
        pop.setProperty("address","学府大道");
        //将pop集合数据写入student.propecties文件中
        pop.store(new FileWriter("D:\\ideaproject\\IO-code\\IO-code-02\\src\\com\\yyh\\properties\\student.properties"),"this is a student");

    }
    public static void main(String[] args) throws IOException {
        Properties pop = new Properties();
        //将jdbc.properties文件中的数据读取到pop集合中
        //pop.load(new FileReader("D:\\ideaproject\\IO-code\\IO-code-02\\src\\com\\yyh\\properties\\student.properties"));
        pop.load(Test3.class.getClassLoader().getResourceAsStream("com/yyh/properties/student.properties"));
        //打印集合中的元素个数
        System.out.println(pop.size());
        //获取集合中的元素
        Set<String> keys = pop.stringPropertyNames();
        for (String key : keys) {
            String value = pop.getProperty(key);
            System.out.println(key + "=" + value);
        }

    }
    public static void main1(String[] args) throws IOException {
        Properties pop = new Properties();
        pop.setProperty("name","张三");
        pop.setProperty("age","18");
        pop.setProperty("score","20.3");
        pop.setProperty("address","学府大道");
        //将pop集合数据写入student.propecties文件中
        pop.store(new FileWriter("D:\\ideaproject\\IO-code\\IO-code-02\\src\\com\\yyh\\properties\\student.properties"),"this is a student");
        //将pop集合数据打印到控制台
        pop.list(System.out);
    }
}
